package br.com.bus.management;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import br.com.bus.management.model.Abastecimento;

public class ListAllBusActivity extends ListActivity implements OnItemClickListener {
	
	String[] ABASTECIMENTOS;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		ABASTECIMENTOS = new String[MainActivity.abastecimentos.size()];
		loadAbastecimentos();
		
		setListAdapter(new ArrayAdapter<String>(this, R.layout.listview_item, ABASTECIMENTOS));
		  
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);

		lv.setOnItemClickListener(this);
	}

	private void loadAbastecimentos() {
		int i = 0;
		for (Abastecimento abs : MainActivity.abastecimentos) {
			ABASTECIMENTOS[i] = abs.toString();
			i++;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> adapter, View view, int pos, long id) {
		 Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
		          Toast.LENGTH_SHORT).show();
	}
	
}
